<template>
  <div>
    <h1>数据列表</h1>
    <button @click="getDataList">获取数据列表</button>
    <button @click="handleDelete(7)">删除</button>
    <button @click="handaddleAdd">添加</button>

  </div>
</template>

<script>

import dataApi from '@/api/data'
import { clone } from 'sortablejs';
export default {

  data() {
    return {
      tableData: [],


    };
  },
  created() {
    this.getDataList();

  },
  methods: {

    async handaddleAdd() {
      console.log('点击添加按钮了');

      let res =await dataApi.addData({
        name: '5',
        value: '4',
        type: '3',
        remark: '2'
      })
       //判断是否成功
       if (res.success) {
        this.$message.success(res.message);
      } else {
        this.$message.error(res.message);
      }
    },


    // 获取数据列表
    async getDataList() {

      let result = await dataApi.getMenuList();
      this.tableData = result.data;
      console.log(result.data)
     
    },
    //删除
    // async handleDelete(row) {

    //   let params = { id: row }
    //   //发送删除请求
    //   let res = await dataApi.deletedata(params)


    // },
    // 物理删除
    async handleDelete(row) {
      //确认是否删除
      let confirm = await this.$myconfirm("确定要删除该数据吗?");
      if (confirm) {
        //发送删除请求
        let res = await dataApi.deletedata({
          id: row
        });
        //判断是否成功
        if (res.success) {
          //成功提示
          this.$message.success(res.message);
        } else {
          //失败提示
          this.$message.error(res.message);
        }
      }
    }
  }
}
</script>

<style></style>